<script setup lang="ts">
let justifyContent = ref<string>('flex-start')
</script>

<template>
  <div class="wrap">
    <h2>沿主轴分配空间</h2>
    <div class="form">
      <label for="justify-content">justify-content:</label>
      <select v-model="justifyContent" name="justify-content" id="justify-content">
        <option value="flex-start">flex-start</option>
        <option value="center">center</option>
        <option value="flex-end">flex-end</option>
        <option value="start">start</option>
        <option value="end">end</option>
        <option value="space-around">space-around</option>
        <option value="space-between">space-between</option>
        <option value="space-evenly">sapce-evenly</option>
        <option value="inherit">inherit</option>
        <option value="initial">initial</option>
        <option value="revert">revert</option>
        <option value="unset">unset</option>
      </select>
    </div>
    <div class="container">
      <div class="item">1</div>
      <div class="item">2</div>
      <div class="item">3</div>
      <div class="item">4</div>
    </div>

    <div class="container">
      <div class="item">1</div>
      <div class="item">2</div>
      <div class="item">3</div>
      <div class="item">4</div>
      <div class="item">5</div>
      <div class="item">6</div>
      <div class="item">7</div>
      <div class="item">8</div>
    </div>
  </div>
</template>

<style scoped lang="scss">
@media (min-width: 760px) {
  .wrap {
    grid-template-columns: repeat(2, 1fr);

    .form {
      grid-column: 1 / span 2;
    }
  }
}
.wrap {
  --justify-content: v-bind(justifyContent);
  width: 100vw;
  min-height: 100vh;
  font-family: "Exo", Arial, sans-serif;
  background-color: #557;
  color: #fff;
  display: grid;
  gap: 1rem;
  align-content: start;
  justify-content: center;
  justify-items: center;
  padding: 1rem;
  .form {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;

    label {
      white-space: nowrap;
      text-align: right;
    }
    select {
      padding: 0.25em 0.5em;
      font-size: inherit;
      min-width: 160px;
    }
  }

  .container {
    background: #ffffff;
    border: 3px solid #88978a;
    border-radius: 7px;

    inline-size: 600px;
    block-size: 300px;
    display: flex;
    flex-wrap: wrap;

    justify-content: var(--justify-content);

    .item {
      background: #e8f0fe;
      border: 2px solid #2938e9;
      border-radius: 4px;
      color: #000;
      display: inline-flex;
      justify-content: center;
      align-items: center;
      inline-size: 88px;
      block-size: 88px;

      &:nth-child(2) {
        background-color: #efe1ff;
      }
      &:nth-child(3) {
        background-color: #bbd7af;
      }
      &:nth-child(4) {
        background-color: #ecbbbb;
      }
      &:nth-child(5) {
        background-color: #00f0ff;
      }
      &:nth-child(6) {
        background-color: #d7af0a;
      }

    }
  }
}
</style>
